/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package minesweeper.components;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JComponent;
import minesweeper.util.Constants;

/**
 *
 * @author cj
 */
public class UI extends JComponent{
    
    protected long startTime;
    protected double currentScore;
    protected double numFlaggedLeft;
    protected boolean gameStarted;
    protected boolean gameRan;

    public UI(int numCol, int numBomb){
        this.setPreferredSize(new Dimension(numCol * Constants.SECTOR_PX_WIDTH, 
                Constants.GAME_UI_PX_HEIGHT));
        
        this.startTime = 0;
        this.currentScore = 0.0;
        this.numFlaggedLeft = numBomb;
        this.gameStarted = false;
        this.gameRan = false;
        
        this.setVisible(true);
    }

    public boolean isGameStarted(){
        return this.gameStarted;
    }

    public boolean hasGameRun(){
        return this.gameRan;
    }
    
    public void startGame(){
        this.gameStarted = true;
        this.gameRan = true;
    }
    
    public void stopGame(){
        this.gameStarted = false;
    }
    
    public void setStartTime(long startTime){
        this.startTime = startTime;
    }
    
    public void setCurrentScore(double currentScore){
        this.currentScore = currentScore;
    }
    
    public void setNumFlaggedLeft(double numFlaggedLeft){
        this.numFlaggedLeft = numFlaggedLeft;
    }
    
    public double getStartTime(){
        return this.startTime;
    }
    
    public double getCurrentScore(){
        return this.currentScore;
    }

    public double getNumFlaggedLeft(){
        return this.numFlaggedLeft;
    }
    
    public void paintComponent(Graphics g){
        g.setColor(Color.BLACK);
        
        if(this.gameStarted){
            g.drawString("Time Elapsed: " + (System.currentTimeMillis() - this.startTime)/1000, 0, 10);
        }else if(this.gameRan){
            g.drawString("Game Over (Press Space for new game).", 0, 10);
        }else{
            g.drawString("Game Not Started.", 0, 10);
        }
        
        g.drawString("Current Score: " + this.currentScore, 0, 22);
        g.drawString("Num Flagged Left: " + this.numFlaggedLeft, 0, 32);
    }

}
